---
title: Purge completed tasks
summary: Batch-remove completed tasks older than a retention window via the PK82036_Task.Task_Purge stored procedure.
status: draft
owner: SAIF Documentation
last_reviewed: 2026-08-21
library: SAIF.Business.Tasks
reference_type: embedded
operation_id: OP-7
trigger: Batch/maintenance caller
---

# Purge completed tasks

This operation deletes previously completed/deleted tasks older than a caller-supplied retention window, by calling `PK82036_Task.Task_Purge`.

| Field | Value |
| --- | --- |
| **Operation ID** | OP-7 |
| **Trigger** | Batch/maintenance caller |
| **Inputs** | Task source code, task category code, retention days |
| **Outputs** | Count of purged rows |
| **Primary components** | `clsTaskCollection.PurgeTasks` (`Shared`) |
| **Entry point** | `SAIF.Business.Tasks/clsTaskCollection.vb` |

## Steps

1. Create a portal request and data request (`DataRequest.ID = "IMG0001_Purge_Task"`), `CommandType = StoredProcedure`, `RequestType = Scalar`, statement `PK82036_Task.Task_Purge` ([SQL-015](../sql/SQL-015-purge-tasks.md), [TASK](../database-tables.md#task)).
2. Add input parameters `intasksourcecode`, `intaskcategorycode`, `inkeepdays` and output parameter `outdelrows` (`DbType.String`, length 15).
   > **Origin**: The `Task_Purge` procedure body resides in the Oracle database and was not retrieved in this analysis pass — the actual retention/purge semantics are unverified.**
3. Call `inDataPortalInfo.ProcessPortalRequest`.
4. Return `CInt(outdelrows)` — the number of deleted rows.

## Process flow

The following diagram visualizes this operation's control flow.

```mermaid
flowchart TD
	Start([PurgeTasks called]) --> S1["Build scalar request:<br>Task_Purge"]
	S1 --> S2["Add source/category/keepdays<br>params + outdelrows output"]
	S2 --> S3["ProcessPortalRequest<br>executes"]
	S3 --> EndOk([Return CInt of outdelrows])
```

## Failure and edge-case behavior

- `inkeepdays` is passed as a string parameter rather than a numeric type*.
- No error handling beyond the framework's default request execution is present in this method — failures are the framework's responsibility**.

## Related documentation
- [Operations and processes](../operations-processes.md)
- [SQL catalog](../sql/index.md)
- [Database tables](../database-tables.md)

> **Note:** Statements marked with * were inferred from code structure, naming conventions, or
> contextual evidence where direct confirmation was not available in source artifacts. Statements
> marked with ** could not be confirmed; treat as unknown until verified.

## Sources
- SAIF.Business.Tasks/clsTaskCollection.vb
